package cn.hdu.liang.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

public class SocketChannelTest {
    public static void main(String[] args) {
        try(SocketChannel socketChannel = SocketChannel.open()) {
            socketChannel.connect(new InetSocketAddress("localhost", 8888));
            ByteBuffer buffer = ByteBuffer.allocate(48);
            Scanner sc = new Scanner(System.in);
            buffer.put(sc.next().getBytes());
            buffer.flip();
            socketChannel.write(buffer);
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}
